#include <stdio.h>
#include <string.h>
              int Tree[10001]; //存储各个节点的父节点
int mark[10001];               //节点是否是树中节点

int findRoot(int node)
{
    if (Tree[node] == -1)
        return node;
    return findRoot(Tree[node]);
}

int main()
{
    int a, b, i;
    int flag = 1;
    int casecount = 1;
    memset(Tree, -1, 10001 * sizeof(int));
    while (scanf("%d%d", &a, &b) != EOF)
    {
        if (a == -1 && b == -1)
            break;
        if (a == 0 && b == 0)
        {
            int count = 0;
            int f = 0;
            for (i = 0; i < 10001; i++)
            {
                if (mark[i] == 1)
                    f = 1;
                if (mark[i] == 1 && Tree[i] == -1)
                    count++;
            }
            if (f == 0)
                printf("Case %d is a tree.\n", casecount);
            else if (count == 1 && flag == 1)
                printf("Case %d is a tree.\n", casecount);
            else
                printf("Case %d is not a tree.\n", casecount);
            casecount++;
            flag = 1;
            // 初始化
            for (i = 0; i < 10001; i++)
            {
                mark[i] = 0;
                Tree[i] = -1;
            }
        }
        else
        {
            mark[a] = 1;
            mark[b] = 1;
            if (Tree[b] != -1 && Tree[b] != a)
            {
                flag = 0;
                continue;
            }
            int rootA = findRoot(a);
            int rootB = findRoot(b);
            if (rootA == rootB)
                flag = 0; //有环
            else
                Tree[b] = a;
        }
    }
    return 0;
}